import { get, dispatcher } from "./core/interceptor";

function getAreaCode(params = {}) {
  return get("/api/areacode", params);
}

/**
 * 获取验证码
 * @param {Object} params {phone}
 * @param {Boolean} loading
 * @returns
 */
function getMsgCode(params = {}, loading = true) {
  return dispatcher({
    method: "post",
    url: "/api/sendvcode",
    params,
    loading,
  });
}

/**
 * 登陆
 * @param {Object} params {phone, msgcode, invite_code?}
 * @param {Boolean} loading
 * @returns
 */
function login(params = {}, loading = true) {
  return dispatcher({
    method: "post",
    url: "/api/login",
    params,
    loading,
  });
}

function logout(params = {}, loading = true) {
  return dispatcher({
    method: "post",
    url: "/api/logout",
    params,
    loading,
  });
}

function userProfile(params = {}, loading = true) {
  return dispatcher({
    url: "/api/user/detail",
    params,
    loading,
  });
}

export { getAreaCode, getMsgCode, login, logout, userProfile };
